<?php include "../public/header.php";?>
<?php include "../public/header_show.php";?>
<style>
    #avatar img{width: 100px;height: 100px}

    .leftavas{width: 50%;float: left;height: 400px;text-align: center;}
    #deatou{border: 1px dashed #eee;width: 100px;height: 100px;display: inline-block;margin-top: 100px;border-radius: 50%}
    #deatou img{width: 100%;height: 100%;border-radius: 50%}
    #upload_avatar{color: #0E0EFF;cursor: pointer;margin: 20px 0 40px 0}
    .deatou_exp{margin: 10px 0}
    #uploadfile{display: none}
</style>
<body id="showPage">
<div id="showBox">
    <div class="page-title">
        <div class="page-title-con">
            <span>个人档案</span>
            <div class="page-title-opt-list">
                <span id="page-close" class="page-close" onclick="layer_close()">×</span>
            </div>
        </div>
    </div>

    <div class="main-container" style="height: 500px;background-color: #FFFFFF">
        <div class="leftavas">

            <div id="deatou">
                <input type="hidden" id="avatar" name="avatar">
                <input type="hidden" id="avatar_id" name="avatar_id">
                <img id="avatar_dea" src="/static/admin/images/avatar.png">
            </div>
            <div class="deatou_exp">
                <input type="file" accept="image/*" id="uploadfile" value="上传头像" />
                <div id="upload_avatar">上传头像</div>
                <div>请上传jpg或png文件,文件大小不超过1M</div>
            </div>


        </div>
        <div class="table-box" style="width: 50%;float: right;clear: unset">
            <div class="title">
                个人信息
            </div>
            <table class="layui-table table-detail">
                <tbody>
                <tr><td>姓名</td><td id="realname"></td></tr>
                <tr><td>登录手机号</td><td id="tel"></td></tr>
                <tr><td>登录密码</td><td>已设置 <span id="updpass" class="colorlan" style="float: right">修改密码</span></td></tr>
                <tr><td>所属部门</td><td id="deptid_name"></td></tr>
                <tr><td>岗位</td><td id="gangid_name"></td></tr>
                <tr><td>角色</td><td id="roleid_name"></td></tr>
                <tr><td>账号状态</td><td id="status_name"></td></tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<script>
    var param_id = getQueryVariable('id') || 0;


    var curHeight = document.body.scrollHeight - 125;
    $(".main-container").css('height', curHeight+'px');


    layui.use(['form', 'layer','element','dropdown'], function() {
        var form = layui.form,element = layui.element;

        facade.ajax({url: ask_userinfo_show, data:{id: param_id}}).done(function(res){
            if (res.code === 2000) {
                var data = res.data;
                $("#realname").text(data.realname);
                $("#tel").text(data.tel);
                $("#deptid_name").text(data.deptid_name);
                $("#gangid_name").text(data.gangid_name);
                $("#roleid_name").text(data.roleid_name);
                $("#status_name").text(data.status_name);
                $("#explain").text(data.explain);
                if(data.avatar){
                    $("#avatar_dea").attr('src',get_file_complete(data.avatar));
                }
                render_from();
            }
        });



        $("#upload_avatar").click(function () {
            $("#uploadfile").click();
        });

        $("#uploadfile").change(function () {
            var loading = layui.layer.load(0, {shade: 0.1});
            let fd = new FormData();
            fd.append('file', this.files[0]);
            fd.append('token', facade.getCookie('token'));
            fd.append('type', 'userinfo');
            $.ajax({
                url: server_api_name+ask_upload_avatar,
                type: "POST",
                data: fd,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (res) {
                    layui.layer.close(loading);
                    if (res.code === 2000) {
                        $("#avatar_dea").attr('src',get_file_complete(res.data.encpath));
                    }else{
                        facade.error(res.data.msg);
                    }
                },
                error: function (res) {
                    layui.layer.close(loading);
                    facade.error("网络错误");
                },
            })
        });


        $("#updpass").click(function () {
            openPageEdit('updpass.php', '770px', '490px');
        });

    });


</script>
</body>
</html>
